package com.foreknow.controller;

import com.mysql.fabric.xmlrpc.base.Data;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**\
 * Servlet服务器端的应用程序
 * 1.需要继承HttpServlet
 * 2.重写doGET/doPost方法
 *  这两个方法会根据前端的请求来调用,如果前端发送的请求是get请求(例如<a>链接</a>),就会自动调用
 *      ServLet中的doget方法
 *      如果前端发送的请求是post请求(例如<form method="post"> 表单<form/>)就会自动调用
 *      ServLet中的dopost方法
 * 3. HttpServletRequest请求对象
 * 4.HttpServletResponse响应对象
 */
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //服务器端向客户端响应的内容的类型
        //编码格式是utf-8
        resp.setContentType("text/html;charset=utf-8");
        //字符流   获取PrintWriter打印流  作用是向网页写一些基本的信息
        PrintWriter out = resp.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>serclet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println(new Date());
        out.println("</body>");
        out.println("</html>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
